malletPCA<-function(mallet.source, output.table, output.graph=NULL, scale.pca=F, group.vector=NULL, draw.circles=F, remove.lines=NULL){
  comp.table<-scan(mallet.source,what="character",sep="\n",quiet=T)
  comp.table<-lapply(comp.table,function(x) unlist(strsplit(x,"\t")))
  comp.table<-do.call("rbind", comp.table)
  comp.table<-as.data.frame(comp.table)
  comp.table[,3:ncol(comp.table)]<-apply(comp.table[,3:ncol(comp.table)],2,function(x) as.numeric(x))
  topic.table<-comp.table[,3:ncol(comp.table)]
  topic.names<-as.character(seq(0,(ncol(topic.table)-1), by=1))
  topic.names<-paste("Topic", topic.names, sep="_")
  colnames(topic.table)<-topic.names
  text.names<-lapply(comp.table[,2], function(x) unlist(strsplit(x, "/")))
  text.names<-unlist(lapply(text.names, function(x) x[length(x)]))
  text.names<-gsub("%20", " ", text.names)
  rownames(topic.table)<-text.names
  if(!is.null(remove.lines)){
    topic.table<-topic.table[-remove.lines,]
    group.vector<-group.vector[-remove.lines]
    text.names<-text.names[-remove.lines]
  }
  topic.pca<-prcomp(topic.table, scale.=scale.pca)
  proportion.var<-summary(topic.pca)
  proportion.var<-proportion.var[[6]]
  proportion.var<-proportion.var[,1:5]
  print(proportion.var)
  topic.pca.cols<-topic.pca$x[,1:5]
  colnames(topic.pca.cols)<-c("PC1", "PC2", "PC3", "PC4", "PC5")
  write.csv(topic.pca.cols, output.table)
  if(!is.null(output.graph)){
    if(is.null(group.vector)){
      pdf(output.graph, height=100, width=100)
      biplot(topic.pca)
      dev.off()
    } else {
      library(ggbiplot)
      pdf(output.graph, height=10, width=10)
      gg.biplot<-ggbiplot(topic.pca, labels=text.names, groups=group.vector, circle=draw.circles)
      print(gg.biplot)
      dev.off()
    }
  } 
  return(topic.pca.cols)
}